package net.zdreamer.geracomium.adapter;

import java.util.List;

import net.zdreamer.geracomium.entity.FoodIndentInfos.Days;
import net.zdreamer.geracomium.entity.FoodIndentInfos.Days.ThreeMeals;
import net.zdreamer.geracomium.entity.FoodIndentInfos.Days.ThreeMeals.Foods;
import net.zdreamer.geracomium.utils.window.ViewControlor;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.geracomium.R;

public class FoodIndentAdapter extends MyBaseAdapter<Days> {
	private FooddaysAdapter dayadapter;

	public FoodIndentAdapter(Context context, List<Days> list, int res) {
		super(context, list, res);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected View getView(int position, View convertView, ViewGroup parent,
			Days value) {
		TextView tv_time = (TextView) convertView.findViewById(R.id.food_time);
		TextView tv_price = (TextView) convertView
				.findViewById(R.id.meals_price);
		ListView daylist = (ListView) convertView
				.findViewById(R.id.food_day_list);
		tv_time.setText(value.time);
		tv_price.setText(value.price);
		dayadapter = new FooddaysAdapter(getmContext(), value.threemeals,
				R.layout.food_meals_list);
		daylist.setAdapter(dayadapter);
		ViewControlor.setListViewHeightBasedOnChildren(daylist);
		return convertView;
	}

	public class FooddaysAdapter extends MyBaseAdapter<ThreeMeals> {
		private FoodMealsAdapter mealadapter;

		public FooddaysAdapter(Context context, List<ThreeMeals> threemeals,
				int res) {
			super(context, threemeals, res);
			// TODO Auto-generated constructor stub
		}

		@Override
		protected View getView(int position, View convertView,
				ViewGroup parent, ThreeMeals value) {
			ImageView img_meals = (ImageView) convertView
					.findViewById(R.id.img_meals);
			ListView meals_list = (ListView) convertView
					.findViewById(R.id.food_meals_list);
			
			img_meals.setImageResource(R.drawable.breakfast);

			mealadapter = new FoodMealsAdapter(getmContext(), value.foods,
					R.layout.food_list);
			meals_list.setAdapter(mealadapter);
			ViewControlor.setListViewHeightBasedOnChildren(meals_list);
			return convertView;
		}

		public class FoodMealsAdapter extends MyBaseAdapter<Foods> {

			public FoodMealsAdapter(Context context, List<Foods> list, int res) {
				super(context, list, res);
			}

			@Override
			protected View getView(int position, View convertView,
					ViewGroup parent, Foods value) {
				TextView food_name = (TextView) convertView
						.findViewById(R.id.food_name);
				TextView food_price = (TextView) convertView
						.findViewById(R.id.food_price);
				ImageView img_price = (ImageView) convertView
						.findViewById(R.id.img_price);
				food_name.setText(value.foodname);
				food_price.setText(value.foodprice);
				img_price.setImageResource(R.drawable.price);
				return convertView;
			}
		}
	}
}
